
/*
Mechanics: Impulses
Science Project (http://scienceproject.codeplex.com)
P. Hurst 2011-2012
*/

(function() {

  $(function() {
    var CloseMenu;
    CloseMenu = function() {
      $("[data-impulses-context-menu-open=true]").attr("data-impulses-context-menu-open", null);
      return $("[data-impulses-context-menu]").remove();
    };
    return $("*").live("click", function(e) {
      var impulseParent, menu;
      switch (e.which) {
        case 1:
          menu = $(this).parents("[data-impulses-context-menu]");
          if (menu.length) {
            e.preventDefault();
            return $.impulses.trigger(this);
          } else {
            return CloseMenu();
          }
          break;
        case 3:
          impulseParent = $(this).parents("[data-impulses]").first();
          if (impulseParent) {
            e.preventDefault();
            return impulseParent.attr("data-impulse-context-menu-open", "true");
          }
      }
    });
  });

}).call(this);
